<template>
  <ele-page>
    <student-search @search="reload"></student-search>
    <ele-card :body-style="{ paddingTop: '8px' }">
      <ele-pro-table ref="tableRef"
                     row-key="StudentId"
                     :columns="columns"
                     :datasource="datasource"
                     :show-overflow-tooltip="true"
                     highlight-current-row
                     cache-key="ORecommendTable"
      >
        <template #action="{ row }">
          <el-link type="primary" :underline="false" @click="showSinglePrintModal(row)">
            打印
          </el-link>
        </template>
      </ele-pro-table>
    </ele-card>
    <print-info-table v-model="singlePrintModalShow" v-if="singlePrintModalShow"
                      :data="currentStudentId"></print-info-table>
  </ele-page>
</template>


<script setup>
import {ref, onMounted} from 'vue';
import StudentSearch from "./components/student-search.vue";
import {ElMessageBox} from 'element-plus/es';
import {EleMessage} from 'ele-admin-plus/es';


import {pageList} from '@/api/manage/orecommend/admin/index.js';


import PrintInfoTable from './components/print-info-table.vue'

/** 表格实例 */
const tableRef = ref(null);
/** 表格列配置 */
const columns = ref([
  {
    type: 'index',
    columnKey: 'index',
    width: 50,
    align: 'center',
    fixed: 'left'
  },
  {
    prop: 'xh',
    label: '学号',
    align: 'center',
    minWidth: 110
  },
  {
    prop: 'sfzh',
    label: '身份证',
    align: 'center',
    minWidth: 110
  },
  {
    prop: 'xm',
    label: '姓名',
    align: 'center',
    minWidth: 110
  },
  {
    prop: 'department',
    label: '系别',
    align: 'center',
    minWidth: 110
  },
  {
    prop: 'majorDirection',
    label: '专业',
    align: 'center',
    minWidth: 110
  },
  {
    prop: 'admissionDate',
    label: '入学时间',
    align: 'center',
    minWidth: 110
  },
  {
    prop: 'leaveDate',
    label: '毕业时间',
    align: 'center',
    minWidth: 110
  },
  {
    prop: 'counsellorName',
    label: '辅导员',
    align: 'center',
    minWidth: 110
  },
  {
    columnKey: 'action',
    label: '操作',
    width: 180,
    align: 'center',
    slot: 'action'
  }
]);


/** 搜索 */
const reload = (where) => {
  tableRef.value?.reload?.({page: 1, where});
};


/** 表格数据源 */
const datasource = ({page, limit, where}) => {
  return pageList({...where, pageNum: page, pageSize: limit});
};


const currentStudentId = ref(null);
const singlePrintModalShow = ref(false);
const showSinglePrintModal = (row) => {
  if (row.studentCheck == '0' || row.studentRecommendSubmit == '0') {
    EleMessage.warning('该生推荐表信息填写不完成，请学生重新填写');
    return;
  }
  currentStudentId.value = row.studentId;
  singlePrintModalShow.value = true;
}


// 页面渲染之后
onMounted(() => {
  // console.log("渲染之后", demo);
})
</script>
